from sanic import response
from sanic import Blueprint

# from my_jinja2.my_jinja2 import template
from mysql_.Orm_DB import *
# from server import data
# from main.view import bp1


bp1 = Blueprint('bp1')
# bp1.static('./snaic_demo', '../static')


@bp1.route('/register', methods=['GET', 'POST'])
async def submit(request):

    username = request.form.get('user')
    password = request.form.get('pwd1')
    print(username)
    print(password)

    nickname = request.form.get('names')
    ques = request.form.get('question')
    ans = request.form.get('answer')

    flag = db_insert_into(username, password, nickname, ques, ans)

    if flag ==False:
        return response.text('fail!')
    else:
        return response.text('success!')


# @bp1.route('/log', methods=['GET', 'POST'])
# async def log(request):
#     if request.method == 'POST':
#         if request.form.get('login') == '登陆':
#             return redirect('login')
#
#         if request.form.get('submit') == '注册':
#             return redirect('/')
#     return template('success.html')

